<?php
	//完成分享接口 doshare.php
	//create by L
	//http://42.121.57.193:7788/platform/doshare.php?id=b7a782741f667201b54880c925faec4b


	//初始化--
	include_once "init.php";

	$md5_phone        	= $_GET["id"];

	if('' == $md5_phone )
	{
		die("-1|ID不可以为空");
	}

	$con = db_connect(DB_NAME);

	//检测share-md5_uuid
	$result = mysql_query("SELECT * from share where md5_phone='$md5_phone'") or die("-1|查询数据库失败");
	$row = mysql_fetch_row($result);

	if (empty($row))
	{
		mysql_close($con);
		die('-1|uuid不存在');
	}

	$phone = $row['0'];
	$flag = $row['3'];
	$share_points	= 10;

	//未处理过的分享--送积分
	if ($flag == 0)
	{
		//根据uuid获取积分-
		$result = mysql_query("SELECT points from user WHERE phone='$phone'") or die("-1|查询user表失败");
		$points_row = mysql_fetch_row($result);

		if (!empty($points_row))
		{
			$db_points = $points_row['0'];
			$current_points  = $db_points + $share_points;
			//更新积分
			$result = mysql_query("UPDATE user SET points='$current_points' WHERE phone='$phone'") or die("-1|更新user失败");
			if ( $result === false )
			{
				mysql_close($con);
				die("-1|增加分享积分失败");
			}
			//更新邀请表中记录的flag值-置为1
			mysql_query("UPDATE share SET flag='1' WHERE phone=$phone") ;
			mysql_close($con);
			echo "0|";
		}
		else
		{
			mysql_close($con);
			echo "-|uuid尚未注册";
		}

	}
	else
	{
		mysql_close($con);
		echo "-1|该用户已经获取过分享积分";
	}


?>
